//package org.darkforest.controller;
//
//import com.wordnik.swagger.annotations.Api;
//import com.wordnik.swagger.annotations.ApiOperation;
//import org.darkforest.auth.CurrentMember;
//import org.darkforest.common.util.DateUtil;
//import org.darkforest.model.Favorites;
//import org.darkforest.model.FavoritesSearchBean;
//import org.darkforest.model.Member;
//import org.darkforest.model.RestEntity;
//import org.darkforest.auth.AuthPassport;
//import org.darkforest.ucenter.service.FavoritesService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// */
//@RestController
//@RequestMapping("favorite")
//@Api(value = "favorite", description = "关注", produces = MediaType.APPLICATION_JSON_VALUE)
//public class FavoriteController {
//    @Autowired
//    private FavoritesService favoritesService;
//    @RequestMapping(value = "list", method = RequestMethod.GET)
//    @AuthPassport
//    @ApiOperation(value = "关注列表", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity favorites(@CurrentMember Member member,
//                                @RequestParam(required = false, defaultValue = "0") Integer start,
//                                @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
//        try {
//            FavoritesSearchBean page = new FavoritesSearchBean();
//            page.setStart(start);
//            page.setMemberId(member.getMemberId());
//            page.setPageSize(pageSize);
//            favoritesService.getFavoritesGoods(page);
//            return RestEntity.success(page.getResultList());
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "/delFavorites", method = RequestMethod.GET)
//    @ApiOperation(value = "移除关注", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity delFavorites(@CurrentMember Member member,  @RequestParam(required = true) Integer[] ids) {
//        try {
//            Map<String, Object> p = new HashMap<String, Object>();
//            p.put("ids", ids);
//            p.put("memberId", member.getMemberId());
//            p.put("type", "goods");
//            favoritesService.delFavorites(p);
//            return RestEntity.success("移除成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//
//    }
//
//    /**
//     * 添加收藏
//     * @return
//     */
//    @AuthPassport
//    @RequestMapping(value = "addFavorites", method = RequestMethod.GET)
//    @ApiOperation(value = "添加关注", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity addFavorites(@CurrentMember Member member, @RequestParam(required = true) Integer goodsCommonId) {
//        try{
//            Favorites favorites = new Favorites();
//            favorites.setMemberId(member.getMemberId());
//            favorites.setFavId(goodsCommonId);
//            List<Favorites> favoritesList = favoritesService.findFavoritesByCondtion(favorites);
//            if (favoritesList.size() < 1) {
//                favorites.setFavType("goods");
//                favorites.setFavTime(DateUtil.unixTimeStampInt().intValue());
//                favoritesService.addFavorites(favorites);
//                return RestEntity.success("添加成功");
//            } else {
//                return RestEntity.success("已关注");
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    /**
//     * 添加收藏
//     * @return
//     */
//    @AuthPassport
//    @RequestMapping(value = "checkIsFavorites", method = RequestMethod.GET)
//    @ApiOperation(value = "验证是否已关注:01 未关注、02 已关注", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity checkIsFavorites(@CurrentMember Member member, @RequestParam(required = true) Integer goodsCommonId) {
//        try{
//            Favorites favorites = new Favorites();
//            favorites.setMemberId(member.getMemberId());
//            favorites.setFavId(goodsCommonId);
//            List<Favorites> favoritesList = favoritesService.findFavoritesByCondtion(favorites);
//            if (favoritesList.size() < 1) {
//                return RestEntity.success("01");
//            } else {
//                return RestEntity.success("02");
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//}
